package controllers;

import models.User;

public class Security extends Secure.Security {

	/**
	 * Extend Play!s security mechanism to authenticate against
	 * the User object.
	 */
	static boolean authenticate(String username, String password) {

		User user = User.all().filter("email", username).get();
		
		//the email should be there
		if (user == null) {
			return false;
		}
		
		//make sure the user confirmed the name
		if (user.confirmationCode.length() != 0) {
			return false;
		}

		return user.isThisCorrectUserPassword(password);

	}

}
